﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using SAP.WebServices;
using System.Collections;
using System.Globalization;
using SAP.Admin.DAO;

namespace SAP
{
    public partial class WeekendTimeSheet : System.Web.UI.Page
    {
        //public static DataSet ds = new DataSet();
        //private static DataSet dsPrjList = new DataSet();
        //private static DataSet dsTaskList = new DataSet();
        //private static string FromDate = DateTime.Now.ToString("MM/dd/yyyy");
        //private static DateTime monday, tuesday, wednesday, thursday, friday, saturday, sunday;

        #region Properties
        #region WeeklyURL
        protected string WeeklyURL
        {
            get { return ViewState["WeeklyURL"].ToString(); }
            set { ViewState["WeeklyURL"] = value; }
        }
        #endregion

        #region dsTaskList
        protected DataSet dsTaskList
        {
            get { return (DataSet)ViewState["dsTaskList"]; }
            set { ViewState["dsTaskList"] = value; }
        }
        #endregion

        #region dsPrjList
        protected DataSet dsPrjList
        {
            get { return (DataSet)ViewState["dsPrjList"]; }
            set { ViewState["dsPrjList"] = value; }
        }
        #endregion

        #region FromDate
        protected string FromDate
        {
            get { return ViewState["FromDate"].ToString(); }
            set { ViewState["FromDate"] = value; }
        }
        #endregion

        #region DaysOfWeek
        protected DateTime Monday
        {
            get { return (DateTime)ViewState["Monday"]; }
            set { ViewState["Monday"] = value; }
        }

        protected DateTime Tuesday
        {
            get { return (DateTime)ViewState["Tuesday"]; }
            set { ViewState["Tuesday"] = value; }
        }

        protected DateTime Wednesday
        {
            get { return (DateTime)ViewState["Wednesday"]; }
            set { ViewState["Wednesday"] = value; }
        }

        protected DateTime Thursday
        {
            get { return (DateTime)ViewState["Thursday"]; }
            set { ViewState["Thursday"] = value; }
        }

        protected DateTime Friday
        {
            get { return (DateTime)ViewState["Friday"]; }
            set { ViewState["Friday"] = value; }
        }

        protected DateTime Saturday
        {
            get { return (DateTime)ViewState["Saturday"]; }
            set { ViewState["Saturday"] = value; }
        }

        protected DateTime Sunday
        {
            get { return (DateTime)ViewState["Sunday"]; }
            set { ViewState["Sunday"] = value; }
        }
        #endregion

        #region ds
        protected DataSet ds
        {
            get { return (DataSet)ViewState["ds"]; }
            set { ViewState["ds"] = value; }
        }
        #endregion
        #endregion

        #region Event

        #region Page_Load
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                ds = new DataSet(); // Set default Day of Week
                if (Request.QueryString["date"] != null && Request.QueryString["date"].Length == 10)
                {
                    FromDate = Request.QueryString["date"];
                }
                else
                {
                    FromDate = DateTime.Now.ToString("MM/dd/yyyy");
                }

                Binding();
                string opt = Request.QueryString["opt"];
                if (opt == "1")
                {
                    btnSubmit.Visible = true;
                    btnAddRecord.Visible = false;
                    WeeklyURL = "/TimeSheet/WeekendTimeSheet.aspx?opt=1";
                }
                else
                {
                    btnSubmit.Visible = false;
                    btnAddRecord.Visible = true;
                    WeeklyURL = "/TimeSheet/WeekendTimeSheet.aspx?opt=0";
                }
            }
        }
        #endregion

        #region lvStage_ItemCommand
        protected void lvStage_ItemCommand(object sender, ListViewCommandEventArgs e)
        {
            DataRow dr = ds.Tables[0].Rows[e.Item.DataItemIndex];
            ListViewItem lvi = e.Item;
            Label lblIDS;
            switch (e.CommandName)
            {
                case "Update":
                    lblIDS = (Label)lvi.FindControl("lblIDSEdit");
                    Save(lblIDS.Text.Split(';'), lvi);
                    break;

                case "Edit":
                    btnAddRecord.Enabled = false;
                    txtFromDate.Enabled = false;
                    break;

                case "Delete":
                    int li_ErrorCode = 0;
                    try
                    {
                        string lsIDSin = dr["IDS"].ToString().Replace(';', ',');

                        SqlHelper.ExecuteNonQuery(Data.ConnectionString, CommandType.Text, "Update tbl_TimeEntry Set [Status] = -1 Where ID in ( " + lsIDSin + " )");
                    }
                    catch (SqlException sqlEx)
                    {
                        li_ErrorCode = sqlEx.ErrorCode;
                    }

                    if (li_ErrorCode != 0)
                    {
                        ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "OKErrors", "Main.setMasterMessage('" + li_ErrorCode.ToString() + "','');", true);
                    }
                    else
                    {
                        Session["successMessage"] = "Operation complete sucessful!";
                        ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "OKErrors", "Main.setMasterMessage('" + "Operation complete sucessful!" + "','');", true);
                        //FromDate = txtFromDate.Text.Trim();
                        Response.Redirect(WeeklyURL + "&date=" + txtFromDate.Text.Trim());
                    } break;

                case "Cancel":
                    //FromDate = txtFromDate.Text.Trim();
                    Response.Redirect(WeeklyURL + "&date=" + txtFromDate.Text.Trim());
                    break;
            }
        }
        #endregion

        #region lvStage_ItemEditing
        protected void lvStage_ItemEditing(object sender, ListViewEditEventArgs e)
        {
            this.lvStage.EditIndex = e.NewEditIndex;
            DataView dv = new DataView(ds.Tables[0]);
            this.lvStage.DataSource = dv;
            this.lvStage.DataBind();
        }
        #endregion

        #region lvStage_ItemDataBound
        protected void lvStage_ItemDataBound(object sender, ListViewItemEventArgs e)
        {
            if (lvStage.EditIndex >= 0)
            {
                ListViewDataItem dataItem = (ListViewDataItem)e.Item;
                if (dataItem.DisplayIndex == lvStage.EditIndex)
                {
                    DropDownList ddl = (DropDownList)e.Item.FindControl("ddl_TaskEdit"); if (ddl != null)
                    {
                        string lsTaskCode = ((Label)e.Item.FindControl("lblTaskCodeEdit")).Text;
                        ddl.DataSource = dsTaskList.Tables[0];
                        ddl.DataTextField = "Name";
                        ddl.DataValueField = "Code";
                        ddl.DataBind();
                        if (!lsTaskCode.Equals("")) ddl.SelectedValue = lsTaskCode;
                    }
                }
                System.Web.UI.HtmlControls.HtmlTableCell td = (System.Web.UI.HtmlControls.HtmlTableCell)e.Item.FindControl("tdButtons");
                if (td != null) td.Visible = true;
            }
            else
            {
                if (e.Item.ItemType == ListViewItemType.DataItem)
                {
                    System.Web.UI.HtmlControls.HtmlTableCell td = (System.Web.UI.HtmlControls.HtmlTableCell)e.Item.FindControl("tdButtons");
                    if (td != null) td.Visible = btnAddRecord.Enabled;
                }
            }
        }
        #endregion

        #region lvStage_LayoutCreated
        protected void lvStage_LayoutCreated(object sender, EventArgs e)
        {
            // calculate Grand Total
            decimal ldecMonTotal = 0, ldecTueTotal = 0, ldecWedTotal = 0, ldecThuTotal = 0, ldecFriTotal = 0, ldecSatTotal = 0, ldecSunTotal = 0, ldecAllTotal = 0;

            foreach (DataRow dr in ds.Tables[0].Rows)
            {
                ldecMonTotal += CS2Dec(dr["Mon"].ToString());
                ldecTueTotal += CS2Dec(dr["Tue"].ToString());
                ldecWedTotal += CS2Dec(dr["Wed"].ToString());
                ldecThuTotal += CS2Dec(dr["Thu"].ToString());
                ldecFriTotal += CS2Dec(dr["Fri"].ToString());
                ldecSatTotal += CS2Dec(dr["Sat"].ToString());
                ldecSunTotal += CS2Dec(dr["Sun"].ToString());
                ldecAllTotal += CS2Dec(dr["Total"].ToString());
            }

            Label lblMonTotal = (Label)lvStage.FindControl("lblMonTotal");
            if (lblMonTotal != null) lblMonTotal.Text = ldecMonTotal.ToString();

            Label lblTueTotal = (Label)lvStage.FindControl("lblTueTotal");
            if (lblTueTotal != null) lblTueTotal.Text = ldecTueTotal.ToString();

            Label lblWedTotal = (Label)lvStage.FindControl("lblWedTotal");
            if (lblWedTotal != null) lblWedTotal.Text = ldecWedTotal.ToString();

            Label lblThuTotal = (Label)lvStage.FindControl("lblThuTotal");
            if (lblThuTotal != null) lblThuTotal.Text = ldecThuTotal.ToString();

            Label lblFriTotal = (Label)lvStage.FindControl("lblFriTotal");
            if (lblFriTotal != null) lblFriTotal.Text = ldecFriTotal.ToString();

            Label lblSatTotal = (Label)lvStage.FindControl("lblSatTotal");
            if (lblSatTotal != null) lblSatTotal.Text = ldecSatTotal.ToString();

            Label lblSunTotal = (Label)lvStage.FindControl("lblSunTotal");
            if (lblSunTotal != null) lblSunTotal.Text = ldecSunTotal.ToString();

            Label lblAllTotal = (Label)lvStage.FindControl("lblAllTotal");
            if (lblAllTotal != null) lblAllTotal.Text = ldecAllTotal.ToString();
        }
        #endregion

        #region OnLoadComplete
        protected override void OnLoadComplete(EventArgs e)
        {  
            try
            {
                base.OnLoadComplete(e);
                if (this.Request["__EVENTARGUMENT"] != null && this.Request["__EVENTARGUMENT"].ToString() != "")
                {
                    Int32 itemNo = 0;
                    DataView dv = new DataView(ds.Tables[0]);
                    switch (this.Request["__EVENTARGUMENT"].ToString())
                    {
                        case "MultiProjectCallBack":
                            ArrayList chosenItems = Session["chosenProject"] as ArrayList;
                            foreach (Project item in chosenItems)
                            {
                                AddUpdateItem(0, item);
                            }

                            this.lvStage.DataSource = dv;
                            this.lvStage.DataBind();
                            break;

                        case "EditProjectCallBack":
                            Project chosenItem = Session["chosenProject"] as Project;
                            itemNo = Int32.Parse(Session["chosenItemNo"] as String);
                            if (chosenItem != null)
                            {
                                AddUpdateItem(itemNo, chosenItem);

                                this.lvStage.DataSource = dv;
                                this.lvStage.EditIndex = ds.Tables[0].Rows.Count-1;
                                this.lvStage.DataBind();
                            }
                            break;

                        default:
                            break;
                    }
                }
                // set day name of week in header
                UpdateListViewHeader();
                EnableButton(); // disable or enable Edit, Delete buttons depend on status
            }
            catch (Exception ex)
            {
                ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "OKErrors", "Main.setMasterMessage('" + ex.ToString() + "','');", true);
                ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "CloseLoading", "Dialog.hideLoader();", true);
            }

            txtFromDate.Text = FromDate;
        }
        #endregion

        #region btnSubmit_Click
        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            UpdateStatus();
        }
        #endregion

        protected void ddl_TaskEdit_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (lvStage.EditIndex < 0) return;
            string TaskCode = ((DropDownList)sender).SelectedValue;

            if (((DropDownList)sender).SelectedIndex >= 0)
            {
                ListViewItem lvi = lvStage.Items[lvStage.EditIndex];
                ((Label)lvi.FindControl("lblTaskCodeEdit")).Text = ((DropDownList)sender).SelectedValue;
                ds.Tables[0].Rows[lvStage.EditIndex]["TaskCode"] = ((DropDownList)sender).SelectedValue;
                ds.Tables[0].Rows[lvStage.EditIndex]["Task"] = ((DropDownList)sender).SelectedItem.Text;
            }
        } 

        #endregion

        #region Methods

        #region Binding
        void Binding()
        {
            txtUserCode.Text = User.Identity.Name;
            txtUserCode.ReadOnly = true;

            CultureInfo ivC = new CultureInfo("es-US");
            DateTime Today = Convert.ToDateTime(FromDate, ivC);
            Monday = Today.AddDays(1 - Today.DayOfWeek.GetHashCode());
            Tuesday = Today.AddDays(2 - Today.DayOfWeek.GetHashCode());
            Wednesday = Today.AddDays(3 - Today.DayOfWeek.GetHashCode());
            Thursday = Today.AddDays(4 - Today.DayOfWeek.GetHashCode());
            Friday = Today.AddDays(5 - Today.DayOfWeek.GetHashCode());
            Saturday = Today.AddDays(6 - Today.DayOfWeek.GetHashCode());
            Sunday = Today.AddDays(7 - Today.DayOfWeek.GetHashCode());

            ds = SqlHelper.ExecuteDataSet(Data.ConnectionString, CommandType.StoredProcedure, "sp_WeekendTimeSheet",
                Data.CreateParameter("@IN_BeginDate", Monday.ToString("MM/dd/yyyy")), Data.CreateParameter("@IN_UserCode", User.Identity.Name));

            string lsSQL = " Select Count(*) From tbl_TimeEntry Where UserCode = '" + User.Identity.Name + "' and [Status] = 0 "
                + " and convert(varchar(8), [Date], 112) >=  '" + Monday.ToString("yyyyMMdd") + "'"
                + " and convert(varchar(8), [Date], 112) <=  '" + Sunday.ToString("yyyyMMdd") + "'";
            if (!CheckStatus(lsSQL) && ds.Tables[0].Rows.Count > 0)
            {
                //btnAddRecord.Enabled = false;
                btnSubmit.Enabled = false;
            }

            DataView dv = new DataView(ds.Tables[0]);
            this.lvStage.DataSource = dv;
            this.lvStage.DataBind();
            LoadPrj();
            LoadTaskList();

            if (ds.Tables[0].Rows.Count <= 0) btnSubmit.Enabled = false;
        }
        #endregion

        #region LoadPrj
        private void LoadPrj()
        {
            dsPrjList = SqlHelper.ExecuteDataSet(Data.ConnectionString, CommandType.StoredProcedure, "sp_ProjectList");
        }
        #endregion

        #region LoadTaskList
        private void LoadTaskList()
        {
            dsTaskList = SqlHelper.ExecuteDataSet(Data.ConnectionString, CommandType.StoredProcedure, "sp_GetTaskList");
        }
        #endregion

        #region AddUpdateItem
        private void AddUpdateItem(Int32 itemNo, Project chosenItem)
        {
            if (chosenItem != null)
            {
                Int32 CurNo = 0;

                DataRow drX;
                if (itemNo == 0)
                {
                    drX = ds.Tables[0].NewRow();
                    CurNo = ds.Tables[0].Rows.Count + 1;
                    drX["No"] = CurNo;
                }
                else
                    drX = ds.Tables[0].Rows[itemNo - 1];

                string lsPrjCode = string.Empty, lsPrjName = string.Empty, lsSAPB1DB = string.Empty, lsTask = string.Empty, lsComments = string.Empty;
                int iNo = ds.Tables[0].Rows.Count + 1;

                if (dsPrjList != null && dsPrjList.Tables != null && dsPrjList.Tables[0].Rows.Count > 0)
                {
                    string[] prjArr = chosenItem.PrjCode.ToString().Split(';');
                    lsPrjName = chosenItem.PrjName;

                    if (prjArr.Length > 1)
                    {
                        lsPrjCode = prjArr[0];
                        lsSAPB1DB = prjArr[1];
                    }
                    else
                    {
                        lsPrjCode = prjArr[0];
                        lsSAPB1DB = "";//SAP DB NAME
                    }
                }

                drX["No"] = iNo.ToString();
                drX["IDS"] = "0;0;0;0;0;0;0";

                drX["UserCode"] = User.Identity.Name;
                drX["Client"] = "";
                drX["PrjCode"] = lsPrjCode;
                drX["OnSite"] = "Yes";
                drX["PrjName"] = lsPrjName;

                drX["Status"] = 0;
                drX["SAPB1DB"] = lsSAPB1DB;
                drX["Task"] = "";
                drX["TaskCode"] = "";
                drX["Comments"] = lsComments;
                drX["Mon"] = 0;
                drX["Tue"] = 0;
                drX["Wed"] = 0;
                drX["Thu"] = 0;
                drX["Fri"] = 0;
                drX["Sat"] = 0;
                drX["Sun"] = 0;
                drX["Total"] = 0;
                drX["Billable"] = 0;

                if (itemNo == 0)
                    ds.Tables[0].Rows.Add(drX);
            }
        }
        #endregion

        #region Save
        private void Save(string[] asIDSArr, ListViewItem lvi)
        {
            if (asIDSArr.Length < 7) return;

            string lsTask = string.Empty;
            string lsTaskCode = string.Empty;

            string lsSAPB1DB = ((Label)lvi.FindControl("lblSAPB1DBEdit")).Text;// lsPrjSAPB1DBArr[1];
            string lsPrjCode = ((Label)lvi.FindControl("lblPrjCodeEdit")).Text;// lsPrjSAPB1DBArr[0];
            string lsPrjName = ((Label)lvi.FindControl("lblPrjNameEdit")).Text;//((DropDownList)lvi.FindControl("ddlPrjTaskEdit")).SelectedItem.Text;
            if (((DropDownList)lvi.FindControl("ddl_TaskEdit")) != null && ((DropDownList)lvi.FindControl("ddl_TaskEdit")).SelectedItem != null)
            {
                lsTask = ((DropDownList)lvi.FindControl("ddl_TaskEdit")).SelectedItem.Text.Trim();//((TextBox)lvi.FindControl("txtTaskEdit")).Text;
                lsTaskCode = ((DropDownList)lvi.FindControl("ddl_TaskEdit")).SelectedItem.Value.Trim();
            }

            string lsComments = ((TextBox)lvi.FindControl("txtCommentsEdit")).Text;

            // Get Hours
            string lsMon = ((TextBox)lvi.FindControl("txtMonEdit")).Text;
            string lsTue = ((TextBox)lvi.FindControl("txtTueEdit")).Text;
            string lsWed = ((TextBox)lvi.FindControl("txtWedEdit")).Text;
            string lsThu = ((TextBox)lvi.FindControl("txtthuEdit")).Text;
            string lsFri = ((TextBox)lvi.FindControl("txtFriEdit")).Text;
            string lsSat = ((TextBox)lvi.FindControl("txtSatEdit")).Text;
            string lsSun = ((TextBox)lvi.FindControl("txtSunEdit")).Text;

            // Get Billable
            int liBillable = (((CheckBox)lvi.FindControl("chkBillableEdit")).Checked == true ? 1 : 0);

            SqlHelper.ExecuteNonQuery(Data.ConnectionString, CommandType.StoredProcedure, "sp_InsUpdTimeEntry",
                Data.CreateParameter("@IN_UserCode", User.Identity.Name),
                Data.CreateParameter("@IN_Monday", Monday.ToString("yyyyMMdd")),
                Data.CreateParameter("@IN_PrjCode", lsPrjCode),
                Data.CreateParameter("@IN_PrjName", lsPrjName),
                Data.CreateParameter("@IN_Task", lsTask),
                Data.CreateParameter("@IN_TaskCode", lsTaskCode),
                Data.CreateParameter("@IN_Comments", lsComments),
                Data.CreateParameter("@IN_SAPB1DB", lsSAPB1DB),
                Data.CreateParameter("@IN_MON", asIDSArr[0] + ";" + CS2Dec(lsMon).ToString() + ";" + liBillable.ToString()),
                Data.CreateParameter("@IN_TUE", asIDSArr[1] + ";" + CS2Dec(lsTue).ToString() + ";" + liBillable.ToString()),
                Data.CreateParameter("@IN_WED", asIDSArr[2] + ";" + CS2Dec(lsWed).ToString() + ";" + liBillable.ToString()),
                Data.CreateParameter("@IN_THU", asIDSArr[3] + ";" + CS2Dec(lsThu).ToString() + ";" + liBillable.ToString()),
                Data.CreateParameter("@IN_FRI", asIDSArr[4] + ";" + CS2Dec(lsFri).ToString() + ";" + liBillable.ToString()),
                Data.CreateParameter("@IN_SAT", asIDSArr[5] + ";" + CS2Dec(lsSat).ToString() + ";" + liBillable.ToString()),
                Data.CreateParameter("@IN_SUN", asIDSArr[6] + ";" + CS2Dec(lsSun).ToString() + ";" + liBillable.ToString())
                );
            Response.Redirect(WeeklyURL + "&date=" + txtFromDate.Text.Trim());
        }
        #endregion

        #region UpdateStatus
        private void UpdateStatus()
        {
            if (ds != null & ds.Tables != null & ds.Tables[0].Rows.Count > 0)
            {
                string lsIDS = string.Empty;

                foreach (DataRow dr in ds.Tables[0].Rows)
                {
                    if (!dr["Status"].ToString().Equals("0")) continue;
                    if (lsIDS.Equals(""))
                        lsIDS = dr["IDS"].ToString();
                    else
                        lsIDS = lsIDS + ";" + dr["IDS"].ToString();
                }
                if (!lsIDS.Equals(""))
                {
                    SqlHelper.ExecuteNonQuery(Data.ConnectionString, CommandType.StoredProcedure, "sp_UpdateTimeEntryStatus", Data.CreateParameter("@IN_IDS", lsIDS), Data.CreateParameter("@IN_Status", "2"));
                    Response.Redirect(WeeklyURL + "&date=" + txtFromDate.Text.Trim());
                }
            }
        }
        #endregion

        #region CS2Dec
        private decimal CS2Dec(string asValue)
        {
            try
            {
                return decimal.Parse(asValue);
            }
            catch (Exception)
            {
                return 0;
            }
        }
        #endregion

        #region UpdateListViewHeader
        protected void UpdateListViewHeader()
        {
            CultureInfo ivCEn = new CultureInfo("en-US");
            Label lblMon = this.lvStage.Controls[0].FindControl("lblMon") as Label;
            if (lblMon != null) lblMon.Text = Monday.ToString("ddd </br> dd-MMM-yy", ivCEn);

            Label lblTue = this.lvStage.Controls[0].FindControl("lblTue") as Label;
            if (lblTue != null) lblTue.Text = Tuesday.ToString("ddd </br> dd-MMM-yy", ivCEn);

            Label lblWed = this.lvStage.Controls[0].FindControl("lblWed") as Label;
            if (lblWed != null) lblWed.Text = Wednesday.ToString("ddd </br> dd-MMM-yy", ivCEn);

            Label lblThu = this.lvStage.Controls[0].FindControl("lblThu") as Label;
            if (lblThu != null) lblThu.Text = Thursday.ToString("ddd </br> dd-MMM-yy", ivCEn);

            Label lblFri = this.lvStage.Controls[0].FindControl("lblFri") as Label;
            if (lblFri != null) lblFri.Text = Friday.ToString("ddd </br> dd-MMM-yy", ivCEn);

            Label lblSat = this.lvStage.Controls[0].FindControl("lblSat") as Label;
            if (lblSat != null) lblSat.Text = Saturday.ToString("ddd </br> dd-MMM-yy", ivCEn);

            Label lblSun = this.lvStage.Controls[0].FindControl("lblSun") as Label;
            if (lblSun != null) lblSun.Text = Sunday.ToString("ddd </br> dd-MMM-yy", ivCEn);
        }
        #endregion

        #region CheckStatus
        private bool CheckStatus(string asSQL)
        {
            SqlDataReader reader = (SqlDataReader)SqlHelper.ExecuteReader(Data.ConnectionString, CommandType.Text, asSQL);
            reader.Read();
            if (int.Parse(reader[0].ToString()) > 0) return true;

            return false;
        }
        #endregion

        #region EnableButton
        private void EnableButton()
        {
            for (int i = 0; i < lvStage.Items.Count; i++)
            {
                ListViewItem lvi = lvStage.Items[i];
                Label lblStatus = (Label)lvi.FindControl("lblStatus");
                if (lblStatus == null) continue;

                if (!lblStatus.Text.Equals("0"))
                {
                    int idx = lvi.Controls.IndexOf((LinkButton)lvi.FindControl("imgbEdit"));
                    LinkButton lbtnEdit = (LinkButton)lvi.FindControl("imgbEdit");
                    LinkButton lbtnDelete = (LinkButton)lvi.FindControl("imgbDelete");
                    lvi.Controls.Remove(lbtnEdit);
                    lvi.Controls.Remove(lbtnDelete);

                    Label lblStatusName = new Label();
                    lblStatusName.ID = "lblStatusName" + i.ToString();
                    if (lblStatus.Text.Equals("1"))
                        lblStatusName.Text = "Approved";
                    else if (lblStatus.Text.Equals("2"))
                        lblStatusName.Text = "Pending";

                    //lblStatusName.Font.Bold = true;
                    lvi.Controls.AddAt(idx, lblStatusName);
                }
            }
        }
        #endregion

        protected void btnFilter_Click(object sender, EventArgs e)
        {
            FromDate = txtFromDate.Text.Trim();
            Response.Redirect(WeeklyURL + "&date=" + txtFromDate.Text.Trim());
        }

        #endregion
    }
}